home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / examples / example03.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  69 lines

  1. /* Illustration of 1-1 scaling for polar plot */
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. main()
  7. {
  8.       int i,j;
  9.       float dtr, theta, dx, dy, r;
  10.       char text[3];
  11.       float x0[361], y0[361];
  12.       float x[361], y[361];
  13.  
  14.       dtr = 3.141592654/180.0;
  15.       for (i=0; i<=360; i++) {
  16.         x0[i] = cos(dtr * i);
  17.         y0[i] = sin(dtr * i);
  18.       }
  19.  
  20.       plstar(1,1);
  21.  
  22. /* Set up viewport and window, but do not draw box */
  23.  
  24.       plenv(-1.3,1.3,-1.3,1.3,1,-2);
  25.       for (i=1; i<=10; i++) {
  26.         for (j=0; j<=360; j++) {
  27.           x[j] = 0.1*i*x0[j];
  28.           y[j] = 0.1*i*y0[j];
  29.         }
  30.  
  31. /* Draw circles for polar grid */
  32.  
  33.         plline(361,x,y);
  34.       }
  35.  
  36.       for (i=0; i<=11; i++) {
  37.         theta = 30.0*i;
  38.         dx = cos(dtr*theta);
  39.         dy = sin(dtr*theta);
  40.  
  41. /* Draw radial spokes for polar grid */
  42.  
  43.         pljoin(0.0,0.0,dx,dy);
  44.         sprintf(text,"%d",round(theta));
  45.  
  46. /* Write labels for angle */
  47.  
  48.         if (dx >= 0) 
  49.           plptex(dx,dy,dx,dy,-0.15,text);
  50.         else
  51.           plptex(dx,dy,-dx,-dy,1.15,text);
  52.       }
  53.  
  54. /* Draw the graph */
  55.  
  56.       for (i=0; i<=360; i++) {
  57.         r = sin(dtr*(5*i));
  58.         x[i] = x0[i] * r;
  59.         y[i] = y0[i] * r;
  60.       }
  61.       plline(361,x,y);
  62.  
  63.       plmtex("t",2.0,0.5,0.5,"\\frPLPLOT Example 3 - r(\\gh)=sin 5\\gh");
  64.  
  65. /* Close the plot at end */
  66.  
  67.       plend();
  68. }
  69.